//
//  CZStatusBottomView.swift
//  CZWeibo
//
//  Created by 左凯旭 on 16/8/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZStatusBottomView: UIView {

    var retweetBtn:UIButton?
    var talkBtn:UIButton?
    var likeBtn:UIButton?
    //供外界赋值使用
    var statusUserModel:CZStatusUserViewModel?{
        
        didSet{
            
            retweetBtn?.setTitle(statusUserModel?.repostsCountStr, forState: UIControlState.Normal)
            talkBtn?.setTitle(statusUserModel?.commentsCountStr, forState: UIControlState.Normal)
            likeBtn?.setTitle(statusUserModel?.attitudesCountStr, forState: UIControlState.Normal)
            
        }
        
    }
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    // MARK: - 设置视图
    func setupUI(){
        backgroundColor = UIColor.whiteColor()
        //添加控件
        retweetBtn = addChildButtons("timeline_icon_retweet", title: "转发")
        talkBtn = addChildButtons("timeline_icon_comment", title: "评论")
        likeBtn = addChildButtons("timeline_icon_unlike", title: "赞")
        let linesOne = addlines()
        let linesTwo = addlines()
        
        
        
        //添加约束
        retweetBtn!.snp_makeConstraints { (make) in
            make.top.bottom.leading.equalTo(self)
            make.width.equalTo(talkBtn!)
        }
        
        talkBtn!.snp_makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetBtn!.snp_trailing)
            make.width.equalTo(likeBtn!)
        }
        
        likeBtn!.snp_makeConstraints { (make) in
            make.top.bottom.trailing.equalTo(self)
            make.leading.equalTo(talkBtn!.snp_trailing)

        }
        
        linesOne.snp_makeConstraints { (make) in
            make.centerX.equalTo(retweetBtn!.snp_trailing)
            make.centerY.equalTo(self)
        }
        
        linesTwo.snp_makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(likeBtn!.snp_leading)
            
    }
    
}
    //添加按钮中间的竖线
    func addlines()->UIImageView{
        let image = UIImageView(imageName: "timeline_card_bottom_line")
        addSubview(image)
        return image
    }
    
    
    
    //添加底部视图的三个按钮
    func addChildButtons(imageName:String,title:String) ->UIButton{
        
        let btn = UIButton()
        
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(15)
        
        btn.setTitle(title, forState: UIControlState.Normal)
        addSubview(btn)
        return btn
    }
    


}
